<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>医生工作站（医嘱管理、病例浏览）</title>
<script type="text/javascript" src="static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" href="static/easyui/themes/metro/easyui.css"/>
<link rel="stylesheet" href="static/easyui/themes/icon.css"/>
</head>
<body>
	<script type="text/javascript">
	$.extend($.fn.datagrid.methods, {
		editCell: function(jq,param){
			return jq.each(function(){
				var opts = $(this).datagrid('options');
				var fields = $(this).datagrid('getColumnFields',true).concat($(this).datagrid('getColumnFields'));
				for(var i=0; i<fields.length; i++){
					var col = $(this).datagrid('getColumnOption', fields[i]);
					col.editor1 = col.editor;
					if (fields[i] != param.field){
						col.editor = null;
						
					}
				}
				$(this).datagrid('beginEdit', param.index);
				
				for(var i=0; i<fields.length; i++){
					var col = $(this).datagrid('getColumnOption', fields[i]);
					col.editor = col.editor1;
				}
			});
		}
	});
	
	var editIndex = undefined;
	function endEditing(){
		if (editIndex == undefined){return true}
		if ($("#adving-record-dg").datagrid('validateRow', editIndex)){
			$("#adving-record-dg").datagrid('endEdit', editIndex);
			editIndex = undefined;
			return true;
		} else {
			return false;
		}
	}
	function onClickCell(index, field){
		if (endEditing()){
			$("#adving-record-dg")
			.datagrid('selectRow', index)
					.datagrid('editCell', {index:index,field:field});
			editIndex = index;
		}
	}
	
	
		$(function(){
			
		    var doctorname = $("#doc-username").val();
			//病人住院的信息
			$("#doc-cash-dg").datagrid({
			    url:'reg-hosprecorddoctor',
			    queryParams:{
			    	doctorname:doctorname
			    },
			    onLoadSuccess: function (data) { 
					if(data==null||data.total ==0){
						$(this).datagrid('appendRow',{
							        hosp_id:'<div style="height:50px;font-size:22px;text-align:center;color:red;line-height:50px;">没有相关记录！该登录人没有病人</div>',
									rownumbers : false
							//合并单元格
						}).datagrid('mergeCells',{
									index : 0,
									field : 'hosp_id',
									colspan : 10
						})
						//隐藏分页导航条
						$(this).closest('div.datagrid-wrap').find('div.datagrid-pager').hide();
					}else{
						$(this).closest('div.datagrid-wrap').find('div.datagrid-pager').show();
					}
	
				}, 
			    method:"Post",
			    pagination:true,
      		    pageNumber:1,
      		    pageSize:5,
      		    pageList:[5,10],
			    columns:[[
			        {field:'hcode',title:'编号',width:100,checkbox:true},
					{field:'hosp_id',title:'住院号',width:120},
					{field:'clinic_name',title:'病人姓名',width:100},
					{field:'clinic_sex',title:'性别',width:80},
					{field:'clinic_age',title:'年龄',width:80},
					{field:'user_name',title:'主治医生',width:120},
					{field:'section_name',title:'科室',width:100},
					{field:'nursename',title:'护士姓名',width:110},
					{field:'sickroom_name',title:'病房号',width:100},
					{field:'bed_no',title:'床位号',width:100},
					{field:'cash_dmoney',title:'押金余额',width:110}
			
			    ]]
			});
			
			//开立医嘱的弹框按钮
			$("#addAdvice").click(function(){
				//获取病人信息表的项
				var hosp_rows =$("#doc-cash-dg").datagrid('getSelected');
				if(hosp_rows == null){
					$.messager.confirm('Confirm', 
							'未选中行，请选择一行', 
							function(r){
					});
				}else{
					//获取住院号
					var hosp_id = hosp_rows["hosp_id"]
					//赋值给住院号的文本框
					$("#hosp_adv_input").textbox('setValue',hosp_id);
					//设置输入框为禁用
					$("#hosp_adv_input").textbox('textbox').attr('readonly',true);  
					$("#hosp_advtype_input").textbox('textbox').attr('readonly',true);  
					//显示开立医嘱的窗口
					$("#advice-win").window("open");
				}
				//清除所有所选的项
			    $("#doc-cash-dg").datagrid('clearChecked');
			});
			
			
			//根据药品名查询
			$("#durgname_input").searchbox({
				searcher:function(value,name){
					    $("#adddrug-dg").datagrid({
						    url:'findall-hospdrug',
						    queryParams:{
						    	drugname:value
						    },
						    pagination:true,
			      		    pageNumber:1,
			      		    pageSize:10,
			      		    pageList:[10,20],
						    columns:[[
						    	{field:'drug_number',title:'编号',width:100,checkbox:true},
								{field:'drug_name',title:'药品名称',width:150},
								{field:'drug_standard',title:'规格',width:100},
								{field:'drug_unit',title:'单位',width:50},
								{field:'drug_retail_price',title:'价格',width:100},
								{field:'type_name',title:'药物类型',width:100,hidden:true}
						    ]]
							
						});
				}
			});
			
			//根据药品的类别查询
			$("input[name='center']").click(function(){
				  if(this.checked){
			          var drugtype =this.value;//当前选中值
				  }
				  $("#adddrug-dg").datagrid({
					    url:'findall-hospdrug',
					    queryParams:{
					    	drugtype:drugtype
					    },
					    pagination:true,
		      		    pageNumber:1,
		      		    pageSize:10,
		      		    pageList:[10,20],
					    columns:[[
					    	{field:'drug_number',title:'编号',width:100,checkbox:true},
							{field:'drug_name',title:'药品名称',width:150},
							{field:'drug_standard',title:'规格',width:100},
							{field:'drug_unit',title:'单位',width:50},
							{field:'drug_retail_price',title:'价格',width:100},
							{field:'type_name',title:'药物类型',width:100,hidden:true}
					    ]]
						
					});
				
			});
		
			//药品信息
			$("#adddrug-dg").datagrid({
			    url:'findall-hospdrug',
			    pagination:true,
      		    pageNumber:1,
      		    pageSize:10,
      		    pageList:[10,20,30],
			    columns:[[
			    	{field:'drug_number',title:'编号',width:100,checkbox:true},
					{field:'drug_name',title:'药品名称',width:150},
					{field:'drug_standard',title:'规格',width:100},
					{field:'drug_unit',title:'单位',width:50},
					{field:'drug_retail_price',title:'价格',width:100},
					{field:'type_name',title:'药物类型',width:100,hidden:true}
			    ]]
				
			});

			//点击药品添加按钮
			$("#adddrugname").click(function(){
				//获取表格中的信息
				var rows =$("#adddrug-dg").datagrid('getSelections');
				var copyRows = [];
	            for (var j= 0; j < rows.length; j++) {
	                copyRows.push(rows[j]); //将数据添加到copyRows数组中
	            }
	            for(var i =0;i<copyRows.length;i++){ 
	            	var falg = true;
	                //获取追加的表格的行
	                var recordrows = $("#adving-record-dg").datagrid("getRows");
	                var total=1; //药品数量
	                 for(var m=0;m<recordrows.length;m++){
	                     //判断该datagrid在将要添加的数据中是否存在
	                     if(copyRows[i].drug_number == recordrows[m].adv_drugno){	      
	                         $("#adving-record-dg").datagrid("updateRow",{
	  							index:m, //行索引
	  						     //行中的某个字段
	  							row:{
	  								adv_drugcount:parseInt(recordrows[m].adv_drugcount)+1
	  							}
	  						});
	                        falg = false;
	                     }
	                 } 
	                 if(falg){
	                	 $("#adving-record-dg").datagrid('appendRow',{
	 		        		adv_drugno:rows[i].drug_number,
	 		        		adv_drugname:rows[i].drug_name,
	 		        		adv_drugprice:rows[i].drug_retail_price,
	 		        		adv_drugcount:parseInt(total),
	 		        		adv_drugtype:rows[i].type_name
		 		         });
	                 }
	                
	            }
	            //清除所有所选的项
		        $("#adddrug-dg").datagrid('clearChecked');
			});
			
			
			//显示药品信息的记录表格
			$("#adving-record-dg").datagrid({
			    url:'',
			    onClickCell:onClickCell,
			    columns:[[
			    	{field:'adv_drugno',title:'药品编号',width:100},
					{field:'adv_drugname',title:'药品名称',width:100},
					{field:'adv_drugcount',title:'数量',width:50,editor:'numberbox'},
					{field:'details_hz',title:'药品用量',width:68,editor:'numberbox'},
					{field:'adv_drugprice',title:'价格',width:50},
					{field:'adv_drugtype',title:'药物类型',width:80}
			    ]],
			    onBeforeEdit:function(index,row){
			        row.editing = true;
			        $("#adving-record-dg").datagrid('refreshRow', index);
			    },
			    onAfterEdit:function(index,row,changes){ 
			    	row.editing = false;
			    	$("#adving-record-dg").datagrid('refreshRow', index);
			    }

			});
			
			//清空显示药品信息表格的按钮
			$("#clear-confirm").click(function(){
	            //获取datalist中所有被选中的数据
	            var record_rows = $("#adving-record-dg").datalist('getChecked');
	            if(record_rows==null){
	            	$.messager.confirm('Confirm', 
							'未选中行，请选择一行', 
							function(r){
					});
	            }
	            
	            if (record_rows.length > 0){
	                var rowsLength = record_rows.length;
	                //删除所有选中的行
	                for (var i = 0; i < rowsLength; i++){
	                    var checkedRow = record_rows[i];            
	                    var checkedRowIndex = $("#adving-record-dg").datalist('getRowIndex', checkedRow);
	                    $("#adving-record-dg").datalist('deleteRow', checkedRowIndex);                
	                }
	            }
	
			});
			//清空所有
			$("#allclear-confirm").click(function(){
	              $("#adving-record-dg").datagrid("loadData", {total:0, rows:[]});
			});
			
			
			//开立医嘱的确定按钮(医嘱表，医嘱详情表，住院表)
			$("#add-hospmedcial").click(function(){
				$('<form method="post" id="addvfor"></from>').appendTo('body').form({
					url:'add-openadvice',
					onSubmit:function(param){
						 var c=$('#addvfor').form("validate");
					      
						param["reg.hospId"] = $("#hosp_adv_input").val();
						//获取医嘱类型
						param["advice.doctorType"] = 1;
						//获取医嘱内容
						param["advice.docadviceConent"] = $("#hospcontent").val();	
						var st = docdatechange($("#s_time").val());
						
						param["advice.docBegintime"] =st;
						var et = docdatechange($("#d_time").val());
						param["advice.docEndtime"] = et;
						//病因
						param["advice.docReason"] = $("#hospseason").val();
						//诊断结果
						param["advice.docResult"] = $("#hospresult").val();
						
						//获取表格中的的详情记录
						var rows = $("#adving-record-dg").datagrid("getRows");
						var drugtotal=null;
						if(rows.length>0){
							for (var i = 0; i < rows.length; i++) {
								//药品编号
								param["details["+i+"].drug.drugNumber"] = rows[i]["adv_drugno"];
								//药品的单个数量
								param["details["+i+"].docdetailsEverynnum"] = rows[i]["adv_drugcount"];
								
								var hz = rows[i]["details_hz"];
								if(typeof(hz)== "undefined"){
									$.messager.confirm('Confirm', 
											'药品用量不能为空', 
											function(r){
									});
									return false;
								}
								
								param["details["+i+"].docdetailsHz"] = rows[i]["details_hz"];

								//药品的总数量
								drugtotal +=parseInt(rows[i]["adv_drugcount"]); 
							}
							param["advice.docDrugallnumber"] = parseInt(drugtotal);	
							
							return c;
						}else{
							$.messager.show({
                                title:'提示信息' , 
                                msg:'验证没有通过,不能提交表单!'
                            });
							return false;
						}
			
					},
					success:function(d){
						$.messager.show({
	                        title:'提示信息' , 
	                        msg:'新增'+d+'!请及时查询医嘱内容'
	                    });
						if(d=="开立医嘱成功"){
							$('#advice-win').window('close');
						}
						$('#addvfor').form("clear");//清空文本
						$("#adving-record-dg").datagrid("loadData", {total:0, rows:[]});
					    //刷新表格
				    	$('#doc-cash-dg').datagrid('reload');
				    	$('#advice-bg').datagrid('reload');
				    	
				    	
					}
				}).submit();

			});
			
			
			//初始化科室下拉表的数据
			$('#sections1').combobox({   
	         	url:'init-hospsection',//数据源
	         	valueField: 'section_id',//实体类名字---主键id
		        textField: 'section_name',//需要显示在下拉框的实际内容
		        editable:false,
	            panelHeight:'auto',//高度根据内容自动定
	            onHidePanel: function(){
	            	var val = $(this).combobox("getData");       
	            },
	            onSelect:function(row){
	            	//护士初始化数据
	    			$('#hospnurse1').combobox({  
			         	url:'init-hospusernurse?sid='+row["section_id"],//数据源
	    	         	valueField: 'user_id',//实体类名字---主键id
	    		        textField: 'user_name',//需要显示在下拉框的实际内容
	    		        editable:false,
	    	            panelHeight:'auto',//高度根据内容自动定
	    	            onLoadSuccess: function () {  //加载完成后,设置选中第一项
	    	                    var val = $(this).combobox("getData");
	    	                    for (var item in val[0]) {
	    	                        if (item == "user_id") {
	    	                        	//初始化数据默认选中第一个
	    	                            $(this).combobox("select", val[0][item]);
	    	                        }
	    	                    }
	    	             }
	     
	    	        });
	            }
	            
	        });
			
			
			
			//初始化手术室
			$('#opretionRoom').combobox({   
	         	url:'init-opreationRoom',//数据源
	         	valueField: 'operationroom_id',//实体类名字---主键id
		        textField: 'operationroom_name',//需要显示在下拉框的实际内容
		        editable:false,
	            panelHeight:'auto',//高度根据内容自动定
	            onHidePanel: function(){
				     $("#opretionType").combobox("setValue",'');
				     var oprid = $('#opretionRoom').combobox('getValue'); 
					 $.ajax({
					 type: "Post",
					 url: "init-opreationType?oprid="+oprid,
					 cache: false,
					 dataType : "json",
					 success: function(data){
						 $("#opretionType").combobox("loadData",data);
			         }
				  }); 
			    }
 
	        });
			//初始化手术类型  
			$('#opretionType').combobox({   
	         	//url:'init-opreationType',//数据源
	         	valueField: 'operationtype_id',//实体类名字---主键id
		        textField: 'operationtype_name',//需要显示在下拉框的实际内容
		        editable:false,
	            panelHeight:'auto',//高度根据内容自动定
	            onLoadSuccess: function () {  //加载完成后,设置选中第一项
	                    var val = $(this).combobox("getData");
	                    for (var item in val[0]) {
	                        if (item == "operationtype_id") {
	                        	//初始化数据默认选中第一个
	                            $(this).combobox("select", val[0][item]);
	                        }
	                    }
	             },
	             onSelect:function(data){
					 $("#futrueprice").textbox('setValue',data['operationtype_price']);
	             }
	          });
			
			
			//安排手术按钮
			$("#in-arrange-op").click(function(){
				//获取病人信息表的项
				var hosp_rows =$("#doc-cash-dg").datagrid('getSelected');
				if(hosp_rows == null){
					$.messager.confirm('Confirm', 
							'未选中行，请选择一行', 
							function(r){
					});
				}else{
					//获取住院号
					var hosp_id = hosp_rows["hosp_id"]
					//获取病人的姓名
					var hosp_sickname = hosp_rows["clinic_name"]
					//赋值给住院号的文本框
					$("#ops_anrr_hospid").textbox('setValue',hosp_id);
					//赋值给病人姓名的文本框
					$("#ops_anrr_sickname").textbox('setValue',hosp_sickname);
					//设置输入框为禁用
					$("#ops_anrr_hospid").textbox('textbox').attr('readonly',true);  
					$("#ops_anrr_sickname").textbox('textbox').attr('readonly',true);  
					//打开手术安排窗口
					$("#arrange-ops-win").window("open");

				}
				//清除所有所选的项
			     $("#doc-cash-dg").datagrid('clearChecked');
			});
			
			
			//手术窗口中的确定按钮
			$("#ops-confirm").click(function(){
				$('#arrange-form').form({
				    url:'add-opsArrange',
				    onSubmit: function(){ 
				    	if(!$('#arrange-form').form('validate')){//调用validate方法校验
                            $.messager.show({
                                title:'提示信息' , 
                                msg:'验证没有通过,不能提交表单!'
                            });
                            return false ;        //当表单验证不通过的时候 必须要return false 
                        }
				    },
				    success:function(date){
				    	if(date=="手术安排新增成功"){
				    		$.messager.show({
		                        title:'提示信息' , 
		                        msg:'新增'+date+'!请去手术管理界面'
		                    });
				 			$('#arrange-form').form("clear");//清空文本
				    		$("#arrange-ops-win").window('close');
				    	}
				    	
				    	if(date=="此时间段已安排"){
				    		$.messager.show({
		                        title:'提示信息' , 
		                        msg:''+date+'!请选择另一个时间段'
		                    });
				    	}
				    	
				    	if(date=="押金余额超出透支"){
				    		$.messager.show({
		                        title:'提示信息' , 
		                        msg:''+date+'!请去押金界面催缴押金'
		                    });
				    	}
						
					    //刷新表格
				    	$('#doc-cash-dg').datagrid('reload');
				    }
				}).submit();
			});
			
			
			
			//安排体检按钮
			$("#addheal_").click(function(){
				//获取病人信息表的项
				var hosp_rows =$("#doc-cash-dg").datagrid('getSelected');
				
				if(hosp_rows == null){
					$.messager.confirm('Confirm', 
							'未选中行，请选择一行', 
							function(r){
					});
				}else{
					//获取住院号
					var hosp_id = hosp_rows["hosp_id"]
					//获取病人的姓名
					var hosp_sickname = hosp_rows["clinic_name"]
					//赋值给住院号的文本框
					$("#heal_hospid").textbox('setValue',hosp_id);
					//赋值给病人姓名的文本框
					$("#heal_sickname").textbox('setValue',hosp_sickname);
					//设置输入框为禁用
					$("#heal_hospid").textbox('textbox').attr('readonly',true);  
					$("#heal_sickname").textbox('textbox').attr('readonly',true);  
					//打开体检窗口
					$("#aarange-heal-win").window("open");
				}
				//清除所有所选的项
			     $("#doc-cash-dg").datagrid('clearChecked');
				
			});
			
			//体检的确定按钮
			$("#doc-addhealpro").click(function(){
				//获取住院号
				var hospid = $("#heal_hospid").val();
				
				//获取体检项目的编号
				var project_rows = $("#doc-healproject-tab").datagrid('getChecked');
				//项目编号的数组
				var project_arr = [];
				//项目的总押金
				var totalmoney=null;
				for(var i=0;i<project_rows.length;i++){
					project_arr.push(project_rows[i].project_no);
					totalmoney +=project_rows[i].project_price;
				}
				parseFloat(totalmoney);
				$.ajax({
					url:'add-health?project_arr='+project_arr+'&hospid='+hospid+'&totalmoney='+totalmoney,
					method:'Post',
					Type:'json',
					success:function(data){
						$.messager.show({
                            title:'提示信息' , 
                            msg:'体检项目新增成功！,请去体检检查界面'
                        });
					}
				});
				//清除选项
				$("#doc-healproject-tab").datagrid('clearChecked');
				$("#aarange-heal-win").window("close");
				$('#doc-cash-dg').datagrid('reload');
				
			});  
			
			//体检项目信息
			$("#doc-healproject-tab").datagrid({
      		    url:'init-healproject',
      		    columns:[[
      		    	   {field:'prolid',title:'',width:40,checkbox:true},
      		    	   {field:'project_no',title:'编号',width:153},
      		    	   {field:'project_name',title:'项目名称',width:164},
      				   {field:'project_price',title:'项目价格',width:150}
      		    ]]
      		});
			
			//病例记录
			$("#ill-tab").datagrid({
			    url:'find-case',
			    pagination:true,
      		    pageNumber:1,
      		    pageSize:10,
      		    pageList:[10,20],
			    columns:[[
					{field:'hosp_id',title:'住院号',width:75},					
					{field:'clinic_name',title:'姓名',width:90},
					{field:'clinic_sex',title:'性别',width:50},
					{field:'user_name',title:'主治医生',width:90},
					{field:'section_name',title:'科室',width:70},
					{field:'doc_reason',title:'病因',width:105},
					{field:'doc_result',title:'诊断结果',width:105},
					{field:'hosp_time',formatter:comFormatDate,title:'入院时间',width:155},
					{field:'out_time',formatter:comFormatDate,title:'出院时间',width:155,
						formatter:function(value,row,index){
							if(row.out_time==null){
								 return "住院中";
							}
							return "已出院";
						 
	   					}
					},
					{field:'out_advice',title:'出院建议',width:150}

			    ]]
			});
			
			//根据查询病例
        	$("#doc-cname").searchbox({
				searcher:function(value,name){
					$("#ill-tab").datagrid({
					  queryParams:{
					    	clinicname:value
					    },
					    url:'find-case',
					    pagination:true,
		      		    pageNumber:1,
		      		    pageSize:10,
		      		    pageList:[10,20],
					    columns:[[
							{field:'hosp_id',title:'住院号',width:80},					
							{field:'clinic_name',title:'姓名',width:100},
							{field:'clinic_sex',title:'性别',width:50},
							{field:'user_name',title:'主治医生',width:100},
							{field:'section_name',title:'科室',width:70},
							{field:'doc_reason',title:'病因',width:105},
							{field:'doc_result',title:'诊断结果',width:105},
							{field:'hosp_time',formatter:comFormatDate,title:'入院时间',width:160},
							{field:'out_time',formatter:comFormatDate,title:'出院时间',width:160,
								formatter:function(value,row,index){
									if(row.out_time==null){
										 return "住院中";
									}
									return "已出院";
								 
			   					}
							},
							{field:'out_advice',title:'出院建议',width:112}

					    ]]
					});
				}
        	
        	});
			
			
        	//医嘱的信息
			$("#advice-bg").datagrid({
			    url:'find-adviceall',
			    pagination:true,
      		    pageNumber:1,
      		    pageSize:5,
      		    pageList:[5,10,15],
			    columns:[[
			    	{field:'docadvice_id',title:'医嘱编号',width:100},
			    	{field:'clinic_name',title:'姓名',width:90},
					{field:'docadvice_conent',title:'医嘱内容',width:200},
					{field:'doc_drugallnumber',title:'药物总数量',width:80},
					{field:'doc_begintime',formatter:comFormatDate,title:'开始时间',width:159},
					{field:'doc_endtime',formatter:comFormatDate,title:'结束时间',width:157},
					{field:'docdetails_type',title:'状态',width:80,
						formatter: function (value, row, index) {
							if(value==0){
				                return "使用中";
							}else if(value==1){
				                return "已执行";
							}else if(value==2){
				                return "已发药";
							}else if(value==3){
				                return "已停用";
							}
			            },
			            styler: function(value,row,index){
			            	if(value==1){
								return 'color:red;';
							}		
						}
						
					},
					{field:'mops',title:'操作',width:180,
   					   formatter:function(value,row,index){
			               var btn ='<a class="adetails easyui-linkbutton" onclick="lookadvicemetial(\''+row.docadvice_id+'\')" href="javascript:void(0)">查看医嘱详情</a>';
   						   return btn;
   					   }
   				   
   				   }
			    ]],
				onLoadSuccess:function(data){
			        $('.adetails').linkbutton({
			        	text:'查看医嘱详情',
			        	plain:true,
			        	iconCls:'icon-check'
			        }); 
			        
			    }  
			});
			
			//设置未执行的颜色
			$("#advice-bg").datagrid({
				rowStyler:function(index,row){
					if (row.docdetails_type==3){
						return 'background-color:#ccc;font-weight:bold;';
					}
				}
			});
			
			
			
        	//查询医嘱
        	$("#docadvice-cname").searchbox({
				searcher:function(value,name){
					$("#advice-bg").datagrid({
					    url:'find-adviceall',
					    queryParams:{
					    	clinicname:value
					    },
					    pagination:true,
		      		    pageNumber:1,
		      		    pageSize:5,
		      		    pageList:[5,10,15],
					    columns:[[
					    	{field:'docadvice_id',title:'医嘱编号',width:100},
					    	{field:'clinic_name',title:'姓名',width:90},
							{field:'docadvice_conent',title:'医嘱内容',width:200},
							{field:'doc_drugallnumber',title:'药物总数量',width:80},
							{field:'doc_begintime',formatter:comFormatDate,title:'开始时间',width:159},
							{field:'doc_endtime',formatter:comFormatDate,title:'结束时间',width:157},
							{field:'docdetails_type',title:'状态',width:80,
								formatter: function (value, row, index) {
									if(value==0){
						                return "使用中";
									}else if(value==1){
						                return "已执行";
									}else if(value==2){
						                return "已停用";
									}
					            },
					            styler: function(value,row,index){
					            	if(value==1){
										return 'color:red;';
									}		
								}
								
							},
							{field:'mops',title:'操作',width:180,
		   					   formatter:function(value,row,index){
					               var btn ='<a class="adetails easyui-linkbutton" onclick="lookadvicemetial(\''+row.docadvice_id+'\')" href="javascript:void(0)">查看医嘱详情</a>';
		   						   return btn;
		   					   }
		   				   
		   				   }
					    ]],
						onLoadSuccess:function(data){
					        $('.adetails').linkbutton({
					        	text:'查看医嘱详情',
					        	plain:true,
					        	iconCls:'icon-check'
					        }); 
					        
					    }  
					});
				}
        	
        	});
			
			
			//医嘱详情的信息
			$("#advice-med-bg").datagrid({
			    url:'',
			    columns:[[
					{field:'docdetails_id',title:'医嘱详情编号',width:100},
					{field:'drug_name',title:'药品名称',width:100},
					{field:'drug_unit',title:'单位',width:100},
					{field:'docdetails_everynnum',title:'药物单个数量',width:100},
					{field:'drug_purchase_price',title:'价格',width:100},
					{field:'type_name',title:'药物类别',width:100}
			    ]]
			});
			
			
		});
		
		//查看医嘱详情
		function lookadvicemetial(docadviceid){
			$("#advice-detial-win").window("open");
			$.ajax({  
                url: 'find-advicedetailsall',  
                data:{'docadviceid':docadviceid},
                type: 'POST',  
                dataType:"json",
			 	success: function (data) {  
	 				//遍历数据前清空datagrid数据
	 				$('#advice-med-bg').datagrid('loadData',{total:0,rows:[]});
	 				//循环订单商品数据
	                for ( var machine in data.result) {
	                    var row_data = {
	    					'docdetails_id' : data.result[machine].docdetails_id,
	                        'drug_name' : data.result[machine].drug_name,
	                        'drug_unit' : data.result[machine].drug_unit,
	                        'docdetails_everynnum' : data.result[machine].docdetails_everynnum,
	                        'drug_purchase_price' : data.result[machine].drug_purchase_price,
	                        'type_name' : data.result[machine].type_name
	                    };
	                    $('#advice-med-bg').datagrid('appendRow', row_data);
	                }
			     }                 
            });    

		};
		
		//安排手术时，查询已在上班的医生
 		 function finddoctor(){
			var daytime = $("#daytime").val();
			var start = $("#starttimeid").val();
			var endt = $("#endtimeid").val();
			var sectionid = $("#sections1").combobox('getValue');
			//医生的初始化数据
	 		$('#hospuserdocid1').combobox({   
	         	url:'select-opsanarrdoctor?daytime='+daytime+'&starttime='+start+'&endtime='+endt+'&sectionid='+sectionid,
	         	valueField: 'user_id',
		        textField: 'user_name',
		        editable:false,
	            panelHeight:'auto',
	            onLoadSuccess: function () {  
	            	 var val = $(this).combobox("getData");
	                    for (var item in val[0]) {
	                        if (item == "user_id") {
	                        	//初始化数据默认选中第一个
	                            $(this).combobox("select", val[0][item]);
	                        }
	                    }
	             }
	        });
		
/* 			$.post('select-opsanarrdoctor',
					{daytime:daytime,starttime:start,endtime:endt,sectionid:sectionid},
					function(result){
						 $("#hospuserdoc1").combobox({   
							  data:result,
							  valueField: 'user_id',
						      textField: 'user_name',
						      editable:false, 
						      panelHeight:'auto' ,
						      onLoadSuccess: function(data){ //加载完成后,设置选中的项 
						    	  console.log(data+"====="+result+"--"+result[0]);
						    	 $("#hospuserdoc1").combobox('select',result[0].user_id);
		                      },
						 });
			},'json');  */
			
		} 

			
		//验证
	   $.extend($.fn.textbox.defaults.rules, {
		   opsreason: {
		        validator: function(value, param) {
		            var reg = /^[\u4e00-\u9fa5]+$/i;
		            return reg.test(value);
		        },
		        message: "项目名称请输入中文"
		    },
		    sick: {
		        validator: function(value, param) {
		            var reg = /^[\u4e00-\u9fa5][a-z,\u4e00-\u9fa5]*/i;
		            return reg.test(value);
		        },
		        message: "项目名称请输入中文"
		    }  
	   });//自定义验证
	
		
		function comFormatDate(date) {
			var day = new Date(date); 
			var Year = 0; 
			var Month = 0; 
			var Day = 0; 
			var CurrentDate = ""; 
			//初始化时间 
			Year= day.getFullYear();
			Month= day.getMonth()+1; 
			Day = day.getDate(); 
			Hour = day.getHours(); 
			 Minute = day.getMinutes(); 
			 Second = day.getSeconds(); 
			CurrentDate += Year + "-"; 
			if (Month >= 10 ) { 
				CurrentDate += Month + "-"; 
			}else { 
				CurrentDate += "0" + Month + "-"; 
			} 
			if (Day >= 10 ) { 
				CurrentDate += Day ; 
			}else { 
				CurrentDate += "0" + Day ; 
			} 
			if(Hour>=10){
				CurrentDate +=" "+Hour;
			}else{
				CurrentDate +=" "+"0"+Hour;
			}
			if(Minute>=10){
				CurrentDate +=":"+Minute;
			}else{
				CurrentDate +=":"+"0"+Minute;
			}
			if(Second>=10){
				CurrentDate +=":"+Second;
			}else{
				CurrentDate +=":"+"0"+Second;
			}
			return CurrentDate; 
		}
		
		function docdatechange(date) {
			var day = new Date(date); 
			var Year = 0; 
			var Month = 0; 
			var Day = 0; 
			var CurrentDate = ""; 
			//初始化时间 
			Year= day.getFullYear();
			Month= day.getMonth()+1; 
			Day = day.getDate(); 
			Hour = day.getHours(); 
			 Minute = day.getMinutes(); 
			 Second = day.getSeconds(); 
			CurrentDate += Year + "-"; 
			if (Month >= 10 ) { 
				CurrentDate += Month + "-"; 
			}else { 
				CurrentDate += "0" + Month + "-"; 
			} 
			if (Day >= 10 ) { 
				CurrentDate += Day ; 
			}else { 
				CurrentDate += "0" + Day ; 
			} 
			if(Hour>=10){
				CurrentDate +=" "+Hour;
			}else{
				CurrentDate +=" "+"0"+Hour;
			}
			if(Minute>=10){
				CurrentDate +=":"+Minute;
			}else{
				CurrentDate +=":"+"0"+Minute;
			}
			if(Second>=10){
				CurrentDate +=":"+Second;
			}else{
				CurrentDate +=":"+"0"+Second;
			}
			return CurrentDate; 
		}
	</script>
	<!-- 选项卡 -->
	<div id="in-tt" class="easyui-tabs">
		<!-- 医生看诊 -->
	    <div title="主治医生" data-options="closable:false" style="overflow:auto;display:none;">
			<fieldset style="border:1px solid #A6A6A6;border-radius:6px;width:1050px;height:350px;margin: 5px auto;">
				<legend>病人信息</legend>
				<input id="doc-username" type="hidden" value="${user.userName}" class="easyui-textbox">
				<table id="doc-cash-dg" class="easyui-datagrid" style="height:320px;" data-options="toolbar:'#doc-open-tb',fitColumns:false,singleSelect:false">
				</table>
	
				
			</fieldset>
			<!-- 医嘱表和医嘱详情表的表格 -->
			<fieldset style="border:1px solid #A6A6A6;border-radius:6px;width:1050px;margin: 5px auto;height:360px;">
				<legend>医嘱项目</legend>
				<p>
				<a>输入姓名查询：<input id="docadvice-cname"  class="easyui-searchbox" style="width:140px;height:25px;"></a>
			    </p>
				<table id="advice-bg" class="easyui-datagrid" data-options="fitColumns:false,singleSelect:false"style="height:280px;margin-top: 10px;">
				</table>
			</fieldset>
		</div>		
	
		
		<!-- 病例浏览 -->
	    <div title="病例浏览" data-options="closable:false" style="overflow:auto;padding:10px;display:none;">
			<fieldset style="border:1px solid #A6A6A6;border-radius:6px;width:1050px;margin: 0px auto;">
				<legend>住院部病例记录</legend>
				<p>
				<a>输入姓名：<input id="doc-cname"  class="easyui-searchbox" style="width:140px;height:25px;"></a>
			    </p>
				<table id="ill-tab" class="easyui-datagrid" data-options="fitColumns:false,singleSelect:false"style="margin-top: 10px;height:380px;">
				</table>
			</fieldset>
	    </div>
	</div>
				

	<!-- 工具栏 -->
	<div id="doc-open-tb">
		<a href="#" id="addAdvice" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">开立医嘱</a>
		<a href="#" id="in-arrange-op" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">安排手术</a>	
		<a href="#" id="addheal_" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">安排体检</a>	
	</div>
	
	<!-- 开立医嘱的窗口 -->
	<div id="advice-win" class="easyui-window" title="新增医嘱" style="width:1000px;height:600px"
	    data-options="iconCls:'icon-save',closed:true,modal:true,shadow:true,resizable:false,collapsible:false,minimizable:false,maximizable:false">
		<fieldset style="border:1px solid #A6A6A6;border-radius:6px;margin-top:6px;margin-left:10px;width:470px;height:490px;float:left;">
			<legend style="font-size:17px;">处方信息</legend>
			<!-- <form id="advfor" method="get"></form> -->
			<div class="doc-adving-mess">
				<p>
					<a><input id="hosp_adv_input" class="easyui-textbox" data-options="label:'住院号',height:25" style="width:230px"></a>
		    		<a><input id="hosp_advtype_input" class="easyui-textbox" data-options="label:'医嘱类型',height:25" value="住院处方" style="width:230px"></a>					
				</p>
				<p>
					<a>
					<input id="s_time" class="easyui-datetimebox" name="docBegintime" data-options="label:'开始时间',height:25,required:true,showSeconds:false" value="" style="width:230px">
					</a>
					<a>
					<input id="d_time" class="easyui-datetimebox" name="docEndtime" data-options="label:'结束时间',height:25,required:true,showSeconds:false" value="" style="width:230px">
					</a>
				</p>
				<p>
					<a><input id="hospseason" class="easyui-textbox" data-options="label:'病因',height:30,required:true,validType:['sick']" style="width:230px"></a>
		    		<a><input id="hospresult" class="easyui-textbox" data-options="label:'诊断结果',height:30,required:true,validType:['sick']" style="width:230px"></a>
				</p>
				<p>
					<a>
					<input id="hospcontent" class="easyui-textbox" data-options="label:'医嘱内容',required:true,validType:['sick']" style="width:460px;height:40px;">
					</a>
				</p>
				<p style="margin-left: 13px;">药品</p>
				<div style="margin-left: 13px;">
					<table id="adving-record-dg" class="easyui-datagrid" data-options="fitColumns:false,singleSelect:false"style="width:450px;height:250px;">
					</table>
				</div>
				<p style="margin-top: 25px;">
					<a id="add-hospmedcial" style="margin-left:50px	;width:140px;" class="easyui-linkbutton" iconCls="icon-ok">确定</a>
					<a id="clear-confirm" style="margin-left:20px;width:90px;" class="easyui-linkbutton" iconCls="icon-close">清空</a>
					<a id="allclear-confirm" style="margin-left:20px;width:90px;" class="easyui-linkbutton" iconCls="icon-close">一键清空</a>
				</p>
			</div>
				
		</fieldset>
	   
			
		<!-- 药品信息 -->
		<fieldset style="border:1px solid #A6A6A6;border-radius:6px;margin-top:6px;margin-left:10px;margin-bottom:20px;width:430px;height:490px;float:left;">
	    	<legend style="font-size:17px;">药品信息</legend>
			<p>
				<a>输入药品名称：<input id="durgname_input"  class="easyui-searchbox" style="width:140px;height:25px;"></a>
				<a id="adddrugname" class="easyui-linkbutton" style="margin-left:30px;width:100px;" iconCls="icon-ok">添加</a>
			</p>
			<p>
				<a>药品类别： <input id="center_drug" name="center" type="checkbox"   value="中药">中药
				           <input id="east_drug"  name="center" type="checkbox"  value="西药">西药
				</a>				 
			</p>
			<div class="nurse-drug" style="margin-top: 10px;">
			    <table id="adddrug-dg" style="height:350px;" class="easyui-datagrid" data-options="fitColumns:false,singleSelect:false">
				</table>
			</div>
	    </fieldset>

	</div>
	
	<!-- 医嘱详情的窗口 -->
	<div id="advice-detial-win" class="easyui-window" title="医嘱详情记录" style="width:620px;height:400px"
	    data-options="iconCls:'icon-save',closed:true,modal:true,shadow:true,resizable:false,collapsible:false,minimizable:false,maximizable:false">
		<!-- 医嘱详情 -->
		<table id="advice-med-bg" style="height:300px;" class="easyui-datagrid" data-options="fitColumns:false,singleSelect:false">
		</table>
	</div>
	
	<!-- 安排手术的窗口 -->
	<div id="arrange-ops-win" class="easyui-window" title="安排手术" style="width:700px;height:510px"
	    data-options="iconCls:'icon-save',closed:true,modal:true,shadow:true,resizable:false,collapsible:false,minimizable:false,maximizable:false">
		<form  id="arrange-form" method="Post" class="ops-form">
			<p style="margin-top: 40px;">
				<a>
				<input id="ops_anrr_hospid" name="hospid" class="easyui-textbox" data-options="label:'住院号',height:30" style="width:230px">
				</a>
	    		<a>
				<input id="ops_anrr_sickname" class="easyui-textbox"  data-options="label:'病人名字',height:30"  style="width:230px">
				</a>
			</p> 
			<p style="margin-top: 30px;">
				<a>
					<select id="sections1" class="easyui-combobox" data-options="label:'科室',height:30" name="sectionname" style="width:230px">
					</select>				
				</a>	
				<a>
					<select id="hospuserdocid1" name="hospdoctorname" class="hospdoc easyui-combobox" data-options="label:'住院医生',height:30"  style="width:230px">
					</select>				
				</a>
			</p>
			<p style="margin-top: 30px;">
				<a>
					<select id="hospnurse1" class="easyui-combobox" data-options="label:'助手姓名',height:30" name="hospnursename" style="width:230px">
					</select>				
				</a>
				<a>
				   <select id="opretionRoom" name="oproom" class="easyui-combobox" data-options="label:'手术室',height:30" style="width:230px">
					</select>	
				</a>
				
			</p>
			<p style="margin-top: 30px;">
				<a>
				   <select id="opretionType" name="optype" class="easyui-combobox" data-options="label:'手术类型',height:30"  style="width:230px">
					</select>	
				</a>
				<a><input  id="futrueprice" class="easyui-textbox" name="futruemoney" data-options="label:'手术预估金额',height:30"  style="width:230px"></a>
				
			</p>
			
			<p style="margin-top: 30px;">
				<a><input id="daytime" class="easyui-datebox" name="dateday" data-options="label:'手术日期',height:30,required:true,showSeconds:false" value="" style="width:230px"></a>
			    <a>
	    		<input id="starttimeid" name="starttime" class="easyui-timespinner" style="width:230px;" required="required" data-options="label:'手术开始时间',height:30,showSeconds:false">
				</a>
			</p>
			<p style="margin-top: 30px;">
				<a>
				<input id="endtimeid" name="endtime" class="easyui-timespinner" style="width:230px;" required="required" data-options="label:'手术结束时间',height:30,showSeconds:false">
				</a>
				<a><input id="opsreason" class="easyui-textbox" name="reason" data-options="label:'手术原因',height:30,required:true,validType:['opsreason'],events:{blur:finddoctor}"  style="width:230px"></a>
			</p>
			<p style="margin-top: 20px;"><a id="ops-confirm" class="easyui-linkbutton" iconCls="icon-ok" style="margin: 20px 290px;width:100px;">确定</a></p>
		</form>
	</div>
	
	<!-- 安排体检窗口 -->
	<div id="aarange-heal-win" class="easyui-window" title="体检" style="width:620px;height:550px"
	    data-options="iconCls:'icon-save',closed:true,modal:true,shadow:true,resizable:false,collapsible:false,minimizable:false,maximizable:false">
	    <p style="margin-top: 20px;">
	        <a style="margin-left: 50px;">
                <span style="margin-right:10px;">住院号</span>
    		    <input id="heal_hospid" name="hospid" class="easyui-textbox" data-options="height:30" style="width:100px">
	        </a>
    		<a style="margin-left: 30px;">
    		   <span style="margin-right:7px;">病人名字</span>
			   <input id="heal_sickname" class="easyui-textbox"  data-options="height:30"  style="width:100px">
			</a>
			<a  id="doc-addhealpro" style="margin-left: 35px;width:100px;" class="a easyui-linkbutton"   data-options="iconCls:'icon-ok',border:false">添加</a> 
		</p> 
	
		<fieldset style="border:1px solid #A6A6A6;border-radius:6px;width:500px;margin-left: 40px;">
			<legend>体检项目</legend>
		     <table id="doc-healproject-tab" class="easyui-datagrid" data-options="fitColumns:false,singleSelect:false,width:500,height:420" > 
			 </table>	
	    </fieldset>
	</div>

	<!-- 弹框提示 -->
    <div id="warmingdoc-win" class="easyui-window"  title="提示框" style="width:300px;height:156px"
    data-options="iconCls:'icon-save',modal:true,resizable:false,collapsible:false,maximizable:false,minimizable:false,closed:true">
          <p class="window-doc" style=" margin-left: 72px;font-size: 16px;margin-top: 47px;">
          </p>
    </div>
    
    <!-- 弹框提示 -->
    <div id="warmingops-win" class="easyui-window"  title="提示框" style="width:300px;height:156px"
    data-options="iconCls:'icon-save',modal:true,resizable:false,collapsible:false,maximizable:false,minimizable:false,closed:true">
          <p class="window-ops" style=" margin-left: 72px;font-size: 16px;margin-top: 47px;">
          </p>
    </div>  
</body>
</html>